<template>
  <div>
    <div class="roomInformation">
      <!-- 搜索 -->
      <el-card class="box-card">
        <div class="clearfix">
          <div class="container">
            <el-form size="small" label-width="100px">
              <el-form-item label="房型名称：" class="width100">
                <el-input
                  v-model="roominfo"
                  placeholder="请输入房型名称"
                  class="selWidth"
                  size="small"
                  clearable
                >
                  <el-button
                    slot="append"
                    icon="el-icon-search"
                    size="small"
                    @click="seachList"
                  />
                </el-input>
              </el-form-item>
            </el-form>
            <div style="margin-left:16px">
              <el-button
                class="mr10"
                size="small"
                type="primary"
                @click="addgInfo()"
                >添加房型</el-button
              >
            </div>
          </div>
        </div>
      </el-card>
      <!-- 列表 -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column fixed prop="fxName" label="房型名称" align="center">
        </el-table-column>
        <el-table-column prop="fjType" label="房间类型" align="center"> </el-table-column>
        <el-table-column prop="galleryful" label="容纳人数" align="center"> </el-table-column>
        <el-table-column prop="remark" label="备注" align="center" show-overflow-tooltip> </el-table-column>
        <el-table-column fixed="right" label="操作" width="300px" align="center">
          <template slot-scope="scope">
            <router-link :to="{ path: '/amszs/roomInformation/roominfoDetail/' + scope.row.id }">
              <el-button
              type="text"
              size="small"
              class="mr10"
              @click="details(scope.row.id)"
              >详情</el-button
            >
            </router-link>
            <router-link :to="{ path: '/amszs/roomInformation/roominfoEadd/' + scope.row.id }">
            <el-button
              type="text"
              size="small"
              class="mr10"
              @click="edit(scope.row)"
              >编辑</el-button
            >
          </router-link>
              <el-button
              type="text"
              size="small"
              class="mr10"
              @click="del(scope.row.id)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="loadData"
          :current-page.sync="pagesize.page"
          :page-sizes="[20, 40, 60, 80]"
          :page-size="pagesize.limit"
          layout="total,sizes,prev, pager, next,jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { roomListApi,delRoomApi } from "@/api/roomtypeInfo";
export default {
  data() {
    return {
      // 列表数据
      tableData: [],
      //  搜索input
      roominfo: "",
      pagesize: {
        // 每页数量
        limit: 20,
        // 页码
        page: 1
      },
      // 总数据量
      total: 0,
      // 总页数
      totalPage: 0
    };
  },
  created() {
    this.loadData();
  },
  methods: {
    // 搜索
   async seachList() {
      const ressl = await roomListApi({fxName:this.roominfo})
      this.tableData = ressl.list
      this.total = this.tableData.length
    },
    //添加房型
    addgInfo() {
      this.$router.push('/amszs/roomInformation/roominfoEadd')
    },
    // 修改
    edit() {},
    // 删除
    async del(id) {
          try {
          await this.$confirm("是否删除该房型", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          });
          await delRoomApi({ id: id });
          this.$message.success("删除成功");
          this.loadData();
        } catch {}
    },
    // 获取房型列表
    async loadData() {
      const res = await roomListApi(this.pagesize);
      this.total = res.total;
      this.totalPage = res.totalPage;
      this.tableData = res.list;
    },
    handleSizeChange(val) {
      this.pagesize.limit = val;
      this.loadData();
    }
  }
};
</script>

<style lang="scss" scoped>
.roomInformation {
  padding: 20px;
  .box-card {
    margin-bottom: 20px;
  }
  .block {
    padding: 20px;
    text-align: right;
    width: 100%;
    background-color: #ffffff;
  }
}
</style>
